//
//  MainTabBarViewController.swift
//  WeiBoSwift
//
//  Created by admin on 2017/11/21.
//  Copyright © 2017年 admin. All rights reserved.
//

import UIKit

class MainTabBarViewController: UITabBarController {

    // lazy var plusButton : UIButton = UIButton.create(imageName: "tabbar_compose_icon_add", backgroundImageName: "tabbar_compose_button")
    lazy var plusButton : UIButton = UIButton.init(imageName: "tabbar_compose_icon_add", backgroundImageName: "tabbar_compose_button")
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //MARK: plus按钮
        setPlusButton()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        setTabBarItem()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

extension MainTabBarViewController {
    private func setTabBarItem () {
        var imageNameArray = ["tabbar_home","tabbar_discover","","tabbar_message_center","tabbar_profile"]
        for i in 0..<tabBar.items!.count {
            let tempItem = tabBar.items![i]
            if i == 2 {
                tempItem.isEnabled = false
                continue
            }
            tempItem.selectedImage = UIImage(named: imageNameArray[i] + "_highlighted")
        }
    }
    
    private func setPlusButton() {
        tabBar.addSubview(plusButton)
        
        plusButton.center = CGPoint.init(x: tabBar.center.x, y: tabBar.bounds.size.height / 2)
        
        plusButton.addTarget(self, action: #selector(plusButtonClick), for: .touchUpInside)
    }
    
    
}

//MARK: 点击事件
extension MainTabBarViewController {
    @objc func plusButtonClick () {
        print("plus click")
    }
}
